
package com.order.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.base.Predicate;
import com.mg.swagger.framework.configuration.EnableSwaggerMgUi;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 支持分组的配置，例如需要给第三方文档、内部使用的文档等分组，上线后只开启第三方文档，内部文档关闭
 * @author 暮光：城中城
 * @since 2018年8月19日
 */
@Configuration
@EnableSwagger2
@EnableSwaggerMgUi
public class SwaggerConfiguration {
	
	// 划重点！！：读取配置文件中是否是线上，如果是线上则关闭文档功能，否则所有接口全部暴露了！
	//Predicate<String> paths = AppConfig.isOnline() ? PathSelectors.none() : PathSelectors.any();
	Predicate<String> paths = false ? PathSelectors.none() : PathSelectors.any();

	@Bean(value = "serverApi")
	public Docket serverApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(serverApiInfo())
				.groupName("服务Api")
				.select()
				.apis(RequestHandlerSelectors.basePackage("com.order.controller"))
				.paths(paths)
				.build();
	}
	
	 
	private ApiInfo serverApiInfo(){
		return new ApiInfoBuilder()
			.title("美团外卖接口测试")
			.description("接口文档")
			.termsOfServiceUrl("")
			.contact(new Contact("cloud", "", "3409922890@qq.com"))
			.version("1.1.1")
			.build();
	}

	

}
